<?php

namespace common\models\datas;

use frontend\models\datas\ClassManage;
use frontend\models\datas\Goods;
use frontend\models\datas\Mechanic;
use frontend\models\datas\Orders;
use Yii;
use common\components\extenders\MenuManage;

/**
 * This is the model class for table "{{%reservation}}".
 *
 * @property integer $id
 * @property integer $customer_id
 * @property integer $student_id
 * @property integer $mechanic_id
 * @property integer $goods_id
 * @property integer $teacher_id
 * @property integer $cate_id
 * @property integer $orders_id
 * @property integer $orders_items_id
 * @property integer $status
 * @property integer $created_at
 * @property integer $salesman_id
 * @property string $mechanic_area
 * @property integer $site_id
 * @property integer $student_age
 */
class Reservation extends \common\components\bases\BaseModel
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%reservation}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'customer_id', 'student_id', 'mechanic_id', 'goods_id', 'teacher_id', 'cate_id', 'orders_id', 'orders_items_id', 'status', 'created_at', 'salesman_id', 'site_id','student_age','send_type'], 'integer'],
            [['mechanic_area'], 'string', 'max' => 50]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'customer_id' => Yii::t('common', '会员id'),
            'student_id' => Yii::t('common', '学生id'),
            'mechanic_id' => Yii::t('common', '机构id'),
            'goods_id' => Yii::t('common', '课程id'),
            'teacher_id' => Yii::t('common', '老师id'),
            'cate_id' => Yii::t('common', '分类id'),
            'orders_id' => Yii::t('common', '订单id'),
            'orders_items_id' => Yii::t('common', '订单详情id'),
            'status' => Yii::t('common', '状态 0 正常 1 不正常'),
            'created_at' => Yii::t('common', '创建时间'),
            'salesman_id' => Yii::t('common', '推荐人id'),
            'mechanic_area' => Yii::t('common', '地区'),
            'site_id' => Yii::t('common', '广场id'),
            'student_age' => Yii::t('common', '学生年龄'),
            'send_type' => Yii::t('common', '卡类型'),
        ];
    }

    public function extraFields(){
        return [
            'operate' => function () {
                return (new MenuManage(MenuManage::RECORD_ITEM_TOOLBAR, $this->attributes))->isDisable(
                    [
                        'update' => function ($data) {
                            return '';
                        }
                    ]
                )->create();
            },
        ];

    }


    public function getStudent(){
        return $this->hasOne(Student::className(), ['id' => 'student_id']);
    }

    public function getCustomer(){
        return $this->hasOne(Customer::className(), ['id' => 'customer_id']);
    }

    public function getMechanic(){
        return $this->hasOne(Mechanic::className(), ['id' => 'mechanic_id']);
    }

    public function getGoods(){
        return $this->hasOne(Goods::className(), ['id' => 'goods_id']);
    }

    public function getOrders(){
        return $this->hasOne(Orders::className(), ['id' => 'orders_id']);
    }

    public function getClassmanage(){
        return $this->hasOne(ClassManage::className(), ['associate_id' => 'goods_id','mechanic_id' => 'mechanic_id']);
    }

    public function getCate(){
        return $this->hasOne(Cate::className(), ['id' => 'cate_id']);
    }

}
